package dp01;

/**
 * 题目：粉刷房子
 * 题目链接：https://leetcode.cn/problems/JEj789/discussion/
 */
public class Solution10 {
    public int minCost(int[][] costs) {
        int n=costs.length;
        int ans[][]=new int[n+1][3];
        for(int i=1;i<=n;i++){
            ans[i][0]=Math.min(ans[i-1][1],ans[i-1][2])+costs[i-1][0];
            ans[i][1]=Math.min(ans[i-1][2],ans[i-1][0])+costs[i-1][1];
            ans[i][2]=Math.min(ans[i-1][1],ans[i-1][0])+costs[i-1][2];
        }
        return Math.min(Math.min(ans[n][0],ans[n][1]),ans[n][2]);
    }
}
